home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Leser 15 / Amiga Plus Leser CD 15.iso / Tools / Development / MosaicSRC / src / gui-menubar.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-03-13  |  29.2 KB  |  846 lines

  1. /****************************************************************************
  2.  * NCSA Mosaic for the X Window System                                      *
  3.  * Software Development Group                                               *
  4.  * National Center for Supercomputing Applications                          *
  5.  * University of Illinois at Urbana-Champaign                               *
  6.  * 605 E. Springfield, Champaign IL 61820                                   *
  7.  * mosaic@ncsa.uiuc.edu                                                     *
  8.  *                                                                          *
  9.  * Copyright (C) 1993, Board of Trustees of the University of Illinois      *
  10.  *                                                                          *
  11.  * NCSA Mosaic software, both binary and source (hereafter, Software) is    *
  12.  * copyrighted by The Board of Trustees of the University of Illinois       *
  13.  * (UI), and ownership remains with the UI.                                 *
  14.  *                                                                          *
  15.  * The UI grants you (hereafter, Licensee) a license to use the Software    *
  16.  * for academic, research and internal business purposes only, without a    *
  17.  * fee.  Licensee may distribute the binary and source code (if released)   *
  18.  * to third parties provided that the copyright notice and this statement   *
  19.  * appears on all copies and that no charge is associated with such         *
  20.  * copies.                                                                  *
  21.  *                                                                          *
  22.  * Licensee may make derivative works.  However, if Licensee distributes    *
  23.  * any derivative work based on or derived from the Software, then          *
  24.  * Licensee will (1) notify NCSA regarding its distribution of the          *
  25.  * derivative work, and (2) clearly notify users that such derivative       *
  26.  * work is a modified version and not the original NCSA Mosaic              *
  27.  * distributed by the UI.                                                   *
  28.  *                                                                          *
  29.  * Any Licensee wishing to make commercial use of the Software should       *
  30.  * contact the UI, c/o NCSA, to negotiate an appropriate license for such   *
  31.  * commercial use.  Commercial use includes (1) integration of all or       *
  32.  * part of the source code into a product for sale or license by or on      *
  33.  * behalf of Licensee to third parties, or (2) distribution of the binary   *
  34.  * code or source code to third parties that need it to utilize a           *
  35.  * commercial product sold or licensed by or on behalf of Licensee.         *
  36.  *                                                                          *
  37.  * UI MAKES NO REPRESENTATIONS ABOUT THE SUITABILITY OF THIS SOFTWARE FOR   *
  38.  * ANY PURPOSE.  IT IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED          *
  39.  * WARRANTY.  THE UI SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY THE    *
  40.  * USERS OF THIS SOFTWARE.                                                  *
  41.  *                                                                          *
  42.  * By using or copying this Software, Licensee agrees to abide by the       *
  43.  * copyright law and all other applicable laws of the U.S. including, but   *
  44.  * not limited to, export control laws, and the terms of this license.      *
  45.  * UI shall have the right to terminate this license immediately by         *
  46.  * written notice upon Licensee's breach of, or non-compliance with, any    *
  47.  * of its terms.  Licensee may be held legally responsible for any          *
  48.  * copyright infringement that is caused or encouraged by Licensee's        *
  49.  * failure to abide by the terms of this license.                           *
  50.  *                                                                          *
  51.  * Comments and questions are welcome and can be sent to                    *
  52.  * mosaic-x@ncsa.uiuc.edu.                                                  *
  53.  ****************************************************************************/
  54.  
  55. #include "includes.h"
  56. #include "globals.h"
  57. #include "HTML.h"
  58. #include "mosaic.h"
  59. #include "libhtmlw/HTML.h"
  60. #include <sys/types.h>
  61. #include <sys/stat.h>
  62.  
  63. extern char *home_document;
  64.  
  65. #define MAX_DOCUMENTS_MENU_ITEMS 120
  66. #define DOCUMENTS_MENU_COUNT_OFFSET 5000
  67. /* List of URL's matching items in documents menu. */
  68. static char *urllist[MAX_DOCUMENTS_MENU_ITEMS];
  69.  
  70.   
  71. /* ------------------------------ menubar_cb ------------------------------ */
  72.  
  73. /*
  74. do_menubar(mo_window *win, int i)
  75. {
  76.   switch (i)
  77.     {
  78.     case mo_reload_document:
  79.       mo_reload_window_text (win, 0);
  80.       break;
  81.     case mo_reload_document_and_images:
  82.       mo_reload_window_text (win, 1);
  83.       break;
  84.     case mo_refresh_document:
  85.       mo_refresh_window_text (win);
  86.       break;
  87.     case mo_re_init:
  88.       mo_re_init_formats ();
  89.       break;
  90.     case mo_clear_image_cache:
  91.       mo_flush_image_cache (win);
  92.       break;
  93.     case mo_document_source:
  94.       mo_post_source_window (win);
  95.       break;
  96.     case mo_search:
  97.       mo_post_search_window (win);
  98.       break;
  99.     case mo_open_document:
  100.       mo_post_open_window (win);
  101.       break;
  102.     case mo_open_local_document:
  103.       mo_post_open_local_window (win);
  104.       break;
  105.     case mo_save_document:
  106.       mo_post_save_window (win);
  107.       break;
  108.     case mo_mail_document:
  109.       mo_post_mail_window (win);
  110.       break;
  111.     case mo_tex_document:
  112.       mo_latex_document (win);
  113.       break;
  114.     case mo_print_document:
  115.       mo_post_print_window (win);
  116.       break;
  117.     case mo_new_window:
  118.       mo_open_another_window (win, home_document, NULL, NULL);
  119.       break;
  120.     case mo_clone_window:
  121.       mo_duplicate_window (win);
  122.       break;
  123.     case mo_close_window:
  124.       mo_delete_window (win);
  125.       break;
  126.     case mo_exit_program:
  127.       mo_post_exitbox ();
  128.       break;
  129. #ifdef HAVE_DTM
  130.     case mo_dtm_open_outport:
  131.       mo_post_dtmout_window (win);
  132.       break;
  133.     case mo_dtm_send_document:
  134.       mo_send_document_over_dtm (win);
  135.       break;
  136. #endif
  137.     case mo_home_document:
  138.       mo_access_document (win, home_document);
  139.       break;
  140.     case mo_network_starting_points:
  141.       mo_access_document (win, NETWORK_STARTING_POINTS_DEFAULT);
  142.       break;
  143.     case mo_internet_metaindex:
  144.       mo_access_document (win, INTERNET_METAINDEX_DEFAULT);
  145.       break;
  146.     case mo_mosaic_demopage:
  147.       mo_open_another_window
  148.         (win, DEMO_PAGE_DEFAULT,
  149.          NULL, NULL);
  150.       break;
  151.     case mo_mosaic_manual:
  152.       mo_open_another_window
  153.         (win, mo_assemble_help_url ("mosaic-docs.html"),
  154.          NULL, NULL);
  155.       break;
  156.  
  157.     case mo_back:
  158.       mo_back_node (win);
  159.       break;
  160.     case mo_forward:
  161.       mo_forward_node (win);
  162.       break;
  163.     case mo_history_list:
  164.       mo_post_history_win (win);
  165.       break;
  166.     case mo_clear_global_history:
  167.       XmxSetUniqid (win->id);
  168.       XmxMakeQuestionDialog
  169.         (win->base, "Are you sure you want to clear the global history?",
  170.          "NCSA Mosaic: Clear Global History", clear_history_confirm_cb, 1, 0);
  171.       XtManageChild (Xmx_w);
  172.       break;
  173.     case mo_hotlist_postit:
  174.       mo_post_hotlist_win (win);
  175.       break;
  176.     case mo_register_node_in_default_hotlist:
  177.       if (win->current_node)
  178.         {
  179.           mo_add_node_to_default_hotlist (win->current_node);
  180.           mo_write_default_hotlist ();
  181.         }
  182.       break;
  183.     case mo_fancy_selections:
  184.       win->pretty = 1 - win->pretty;
  185.       mo_set_fancy_selections_toggle (win);
  186.       HTMLClearSelection (win->scrolled_win);
  187.       XmxSetArg (WbNfancySelections, win->pretty ? True : False);
  188.       XmxSetValues (win->scrolled_win);
  189.       break;
  190.     case mo_binary_transfer:
  191.       win->binary_transfer =
  192.         (win->binary_transfer ? 0 : 1);
  193.       break;
  194.     case mo_delay_image_loads:
  195.       win->delay_image_loads =
  196.         (win->delay_image_loads ? 0 : 1);
  197.       XmxSetArg (WbNdelayImageLoads, win->delay_image_loads ? True : False);
  198.       XmxSetValues (win->scrolled_win);
  199.       XmxRSetSensitive (win->menubar, mo_expand_images_current,
  200.                         win->delay_image_loads ? XmxSensitive : XmxNotSensitive);
  201.       break;
  202.     case mo_expand_images_current:
  203.       XmxSetArg (WbNdelayImageLoads, False);
  204.       XmxSetValues (win->scrolled_win);
  205.       mo_refresh_window_text (win);
  206.       XmxSetArg (WbNdelayImageLoads, win->delay_image_loads ? True : False);
  207.       XmxSetValues (win->scrolled_win);
  208.       break;
  209.     case mo_large_fonts:
  210.     case mo_regular_fonts:
  211.     case mo_small_fonts:
  212.     case mo_large_helvetica:
  213.     case mo_regular_helvetica:
  214.     case mo_small_helvetica:
  215.     case mo_large_newcentury:
  216.     case mo_regular_newcentury:
  217.     case mo_small_newcentury:
  218.     case mo_large_lucidabright:
  219.     case mo_regular_lucidabright:
  220.     case mo_small_lucidabright:
  221.       mo_set_fonts (win, i);
  222.       break;
  223.     case mo_default_underlines:
  224.     case mo_l1_underlines:
  225.     case mo_l2_underlines:
  226.     case mo_l3_underlines:
  227.     case mo_no_underlines:
  228.       mo_set_underlines (win, i);
  229.       break;
  230.     case mo_help_about:
  231.       mo_open_another_window
  232.         (win, mo_assemble_help_url ("help-about.html"),
  233.          NULL, NULL);
  234.       break;
  235.     case mo_help_onwindow:
  236.       mo_open_another_window
  237.         (win, mo_assemble_help_url ("help-on-docview-window.html"),
  238.          NULL, NULL);
  239.       break;
  240.     case mo_whats_new:
  241.       mo_open_another_window
  242.         (win, WHATSNEW_PAGE_DEFAULT,
  243.          NULL, NULL);
  244.       break;
  245.     case mo_help_onversion:
  246.       mo_open_another_window
  247.         (win, MO_HELP_ON_VERSION_DOCUMENT,
  248.          NULL, NULL);
  249.       break;
  250.     case mo_help_faq:
  251.       mo_open_another_window (win, mo_assemble_help_url ("mosaic-faq.html"), 
  252.                               NULL, NULL);
  253.       break;
  254.     case mo_help_html:
  255.       mo_open_another_window (win, HTMLPRIMER_PAGE_DEFAULT, 
  256.                               NULL, NULL);
  257.       break;
  258.     case mo_help_url:
  259.       mo_open_another_window (win, URLPRIMER_PAGE_DEFAULT, 
  260.                               NULL, NULL);
  261.       break;
  262.     case mo_whine:
  263.       mo_post_whine_win (win);
  264.       break;
  265.     case mo_annotate:
  266.       mo_post_annotate_win (win, 0, 0, NULL, NULL, NULL, NULL);
  267.       break;
  268. #ifdef HAVE_AUDIO_ANNOTATIONS
  269.     case mo_audio_annotate:
  270.       mo_post_audio_annotate_win (win);
  271.       break;
  272. #endif
  273.     case mo_annotate_edit:
  274.       /* OK, let's be smart.
  275.          If we get here, we know we're viewing an editable
  276.          annotation.
  277.          We also know the filename (just strip the leading
  278.          file: off the URL).
  279.          We also know the ID, by virtue of the filename
  280.          (just look for PAN-#.html. */
  281.       if (win->current_node)
  282.         {
  283.           char *author, *title, *text, *fname;
  284.           int id;
  285.           
  286.           if (win->current_node->annotation_type == mo_annotation_private)
  287.             {
  288.               mo_grok_pan_pieces (win->current_node->url,
  289.                                   win->current_node->text,
  290.                                   &title, &author, &text, 
  291.                                   &id, &fname);
  292.               
  293.               mo_post_annotate_win (win, 1, id, title, author, text, fname);
  294.             }
  295.           else if (win->current_node->annotation_type == mo_annotation_workgroup)
  296.             {
  297.               mo_grok_grpan_pieces (win->current_node->url,
  298.                                     win->current_node->text,
  299.                                     &title, &author, &text, 
  300.                                     &id, &fname);
  301.               mo_post_annotate_win (win, 1, id, title, author, text, fname);
  302.             }
  303.         }
  304.       break;
  305.     case mo_annotate_delete:
  306.       if (Rdata.confirm_delete_annotation)
  307.         {
  308.           XmxSetUniqid (win->id);
  309.           XmxMakeQuestionDialog
  310.             (win->base, "Are you sure you want to delete this annotation?",
  311.              "NCSA Mosaic: Delete Annotation", delete_annotation_confirm_cb, 1, 0);
  312.           XtManageChild (Xmx_w);
  313.         }
  314.       else
  315.         mo_do_delete_annotation (win);
  316.       break;
  317.     default:
  318.       if (i >= DOCUMENTS_MENU_COUNT_OFFSET)
  319.         mo_access_document (win, urllist[i - DOCUMENTS_MENU_COUNT_OFFSET]);
  320.       break;
  321.     }
  322.  
  323.   return;
  324. }
  325. */
  326. /* ---------------------------- file_menuspec ----------------------------- */
  327.  
  328. #if 0
  329. static XmxMenubarStruct file_menuspec[] =
  330. {
  331.   { "New Window",         'N', menubar_cb, mo_new_window },
  332.   { "Clone Window",       'C', menubar_cb, mo_clone_window },
  333.   { "----" },
  334.   { "Open...",            'O', menubar_cb, mo_open_document },
  335.   { "Open Local...",      'L', menubar_cb, mo_open_local_document },
  336.   { "----" },
  337.   { "Save As...",         'A', menubar_cb, mo_save_document },
  338.   { "Mail To...",         'M', menubar_cb, mo_mail_document },
  339.   { "Print...",           'P', menubar_cb, mo_print_document },
  340. #ifdef HAVE_DTM
  341.   { "----" },
  342.   { "Open DTM Outport...",    'T', menubar_cb, mo_dtm_open_outport },
  343.   { "Broadcast Document",     'B', menubar_cb, mo_dtm_send_document },
  344. #endif /* HAVE_DTM */
  345.   { "----" },
  346.   { "Search...",          'S', menubar_cb, mo_search },
  347.   { "Reload",             'R', menubar_cb, mo_reload_document },
  348.   { "Refresh",            'f', menubar_cb, mo_refresh_document },
  349.   { "Source Document...", 'D', menubar_cb, mo_document_source },
  350.   { "----" },
  351.   { "Reload Config Files", 'n', menubar_cb, mo_re_init },
  352.   { "Clear Image Cache",       'I', menubar_cb, mo_clear_image_cache },
  353.   { "----" },
  354.   { "Close Window",       'W', menubar_cb, mo_close_window },
  355.   { "Exit Program...",    'E', menubar_cb, mo_exit_program },
  356.   { NULL },
  357. };
  358.  
  359. static XmxMenubarStruct navi_menuspec[] =
  360. {
  361.   { "Back",                    'B', menubar_cb, mo_back },
  362.   { "Forward",                 'F', menubar_cb, mo_forward },
  363.   { "----" },   
  364.   { "Open...",                 'O', menubar_cb, mo_open_document },
  365.   { "Open Local...",           'L', menubar_cb, mo_open_local_document },
  366.   { "----" },
  367.   { "Home Document",           'D', menubar_cb, mo_home_document },
  368.   { "Network Starting Points", 'N', menubar_cb, mo_network_starting_points },
  369.   { "----" },   
  370.   { "Window History...",       'W', menubar_cb, mo_history_list },
  371.   { "Clear Global History...",     'C', menubar_cb, mo_clear_global_history },
  372.   { "----" },
  373.   { "Hotlist...",              'H', menubar_cb, mo_hotlist_postit },
  374.   { "Add Document To Hotlist", 'A', menubar_cb, mo_register_node_in_default_hotlist },
  375.   { NULL },
  376. };
  377.  
  378. static XmxMenubarStruct fnts_menuspec[] =
  379. {
  380.   { "<Large Times Fonts",          'L', menubar_cb, mo_large_fonts },
  381.   { "<Large Helvetica Fonts",      'H', menubar_cb, mo_large_helvetica },
  382.   { "<Large New Century Fonts",    'N', menubar_cb, mo_large_newcentury },
  383.   { "<Large Lucida Bright Fonts",  'B', menubar_cb, mo_large_lucidabright },
  384.   { "----" },
  385.   { "<Small Times Fonts",          'S', menubar_cb, mo_small_fonts },
  386.   { "<Small Helvetica Fonts",      'e', menubar_cb, mo_small_helvetica },
  387.   { "<Small New Century Fonts",    'C', menubar_cb, mo_small_newcentury },
  388.   { "<Small Lucida Bright Fonts",  'F', menubar_cb, mo_small_lucidabright },
  389.   { NULL },
  390. };
  391.  
  392. static XmxMenubarStruct undr_menuspec[] =
  393. {
  394.   { "<Default Underlines",         'D', menubar_cb, mo_default_underlines },
  395.   { "<Light Underlines",           'L', menubar_cb, mo_l1_underlines },
  396.   { "<Medium Underlines",          'M', menubar_cb, mo_l2_underlines },
  397.   { "<Heavy Underlines",           'H', menubar_cb, mo_l3_underlines },
  398.   { "<No Underlines",              'N', menubar_cb, mo_no_underlines },
  399.   { NULL },
  400. };
  401.  
  402. static XmxMenubarStruct opts_menuspec[] =
  403. {
  404.   { "#Fancy Selections",           'F', menubar_cb, mo_fancy_selections },
  405.   { "#Binary Transfer Mode",       'B', menubar_cb, mo_binary_transfer },
  406.   { "----" },
  407.   { "<Times (Default) Fonts",      'T', menubar_cb, mo_regular_fonts },
  408.   { "<Helvetica Fonts",            'H', menubar_cb, mo_regular_helvetica },
  409.   { "<New Century Fonts",          'N', menubar_cb, mo_regular_newcentury },
  410.   { "<Lucida Bright Fonts",        'L', menubar_cb, mo_regular_lucidabright },
  411.   { "More Fonts",                  'M', NULL, NULL, fnts_menuspec },
  412.   { "----" },
  413.   { "Anchor Underlines",           'A', NULL, NULL, undr_menuspec }, 
  414.   { NULL },
  415. };
  416.  
  417. static XmxMenubarStruct help_menuspec[] =
  418. {
  419.   { "About...",      'A', menubar_cb, mo_help_about },
  420.   { "Manual...",     'M', menubar_cb, mo_mosaic_manual },
  421.   { "----" },
  422.   { "What's New...", 'W', menubar_cb, mo_whats_new },
  423.   { "Demo...",       'D', menubar_cb, mo_mosaic_demopage },
  424.   { "----" },
  425.   { "On Version...", 'V', menubar_cb, mo_help_onversion },
  426.   { "On Window...",  'O', menubar_cb, mo_help_onwindow },
  427.   { "On FAQ...",     'F', menubar_cb, mo_help_faq },
  428.   { "----" },
  429.   { "On HTML...",    'H', menubar_cb, mo_help_html },
  430.   { "On URLs...",    'U', menubar_cb, mo_help_url },
  431.   { "----" },
  432.   { "Mail Developers...",   'M', menubar_cb, mo_whine },
  433.   { NULL },
  434. };
  435.  
  436. static XmxMenubarStruct anno_menuspec[] =
  437. {
  438.   { "Annotate...",              'A', menubar_cb, mo_annotate },
  439. #ifdef HAVE_AUDIO_ANNOTATIONS
  440.   { "Audio Annotate...",        'u', menubar_cb, mo_audio_annotate },
  441. #endif
  442.   { "----" },
  443.   { "Edit This Annotation...",  'E', menubar_cb, mo_annotate_edit },
  444.   { "Delete This Annotation...",'D', menubar_cb, mo_annotate_delete },
  445.   { NULL },
  446. };
  447.  
  448. static XmxMenubarStruct menuspec[] =
  449. {
  450.   { "File",      'F', NULL, NULL, file_menuspec },
  451.   { "Navigate",  'N', NULL, NULL, navi_menuspec },
  452.   { "Options",   'O', NULL, NULL, opts_menuspec },
  453.   { "Annotate",  'A', NULL, NULL, anno_menuspec },
  454.   { "Help",      'H', NULL, NULL, help_menuspec },
  455.   /* Dummy submenu. */
  456.   { NULL,       NULL, NULL, NULL, NULL },
  457.   { NULL },
  458. };
  459. #endif
  460.  
  461. /* ------------------------------------------------------------------------ */
  462. /* --------------------------- Colleen menubar ---------------------------- */
  463. /* ------------------------------------------------------------------------ */
  464.  
  465. #if 0
  466. static XmxMenubarStruct file_menuspecc[] =
  467. {
  468.   { "New Window",         'N', menubar_cb, mo_new_window },
  469.   { "Clone Window",       'C', menubar_cb, mo_clone_window },
  470.   { "----" },
  471.   { "Open URL...",        'O', menubar_cb, mo_open_document },
  472.   { "Open Local...",      'L', menubar_cb, mo_open_local_document },
  473.   { "----" },
  474.   { "Reload Current",     'R', menubar_cb, mo_reload_document },
  475.   { "Reload Images",      'a', menubar_cb, mo_reload_document_and_images },
  476.   { "Refresh Current",    'f', menubar_cb, mo_refresh_document },
  477.   { "----" },
  478.   { "Find In Current...", 'I', menubar_cb, mo_search },
  479.   { "View Source...",     'V', menubar_cb, mo_document_source },
  480.   { "----" },
  481.   { "Save As...",         'S', menubar_cb, mo_save_document },
  482.   { "Print...",           'P', menubar_cb, mo_print_document },
  483.   { "Mail To...",         'M', menubar_cb, mo_mail_document },
  484. #ifdef HAVE_DTM
  485.   { "----" },
  486.   { "Open DTM Outport...",'D', menubar_cb, mo_dtm_open_outport },
  487.   { "Broadcast Over DTM", 'B', menubar_cb, mo_dtm_send_document },
  488. #endif /* HAVE_DTM */
  489.   { "----" },
  490.   { "Close Window",       'W', menubar_cb, mo_close_window },
  491.   { "Exit Program...",    'E', menubar_cb, mo_exit_program },
  492.   { NULL },
  493. };
  494.  
  495. static XmxMenubarStruct fnts_menuspec[] =
  496. {
  497.   { "<Times Regular",              'T', menubar_cb, mo_regular_fonts },
  498.   { "<Times Small",                'S', menubar_cb, mo_small_fonts },
  499.   { "<Times Large",                'L', menubar_cb, mo_large_fonts },
  500.   { "----" },
  501.   { "<Helvetica Regular",          'H', menubar_cb, mo_regular_helvetica },
  502.   { "<Helvetica Small",            'e', menubar_cb, mo_small_helvetica },
  503.   { "<Helvetica Large",            'v', menubar_cb, mo_large_helvetica },
  504.   { "----" },
  505.   { "<New Century Regular",        'N', menubar_cb, mo_regular_newcentury },
  506.   { "<New Century Small",          'w', menubar_cb, mo_small_newcentury },
  507.   { "<New Century Large",          'C', menubar_cb, mo_large_newcentury },
  508.   { "----" },
  509.   { "<Lucida Bright Regular",      'L', menubar_cb, mo_regular_lucidabright },
  510.   { "<Lucida Bright Small",        'u', menubar_cb, mo_small_lucidabright },
  511.   { "<Lucida Bright Large",        'i', menubar_cb, mo_large_lucidabright },
  512.   { NULL },
  513. };
  514.  
  515. static XmxMenubarStruct undr_menuspec[] =
  516. {
  517.   { "<Default Underlines",         'D', menubar_cb, mo_default_underlines },
  518.   { "<Light Underlines",           'L', menubar_cb, mo_l1_underlines },
  519.   { "<Medium Underlines",          'M', menubar_cb, mo_l2_underlines },
  520.   { "<Heavy Underlines",           'H', menubar_cb, mo_l3_underlines },
  521.   { "<No Underlines",              'N', menubar_cb, mo_no_underlines },
  522.   { NULL },
  523. };
  524.  
  525. static XmxMenubarStruct opts_menuspec[] =
  526. {
  527.   { "#Fancy Selections",           'S', menubar_cb, mo_fancy_selections },
  528.   { "----" },
  529.   { "#Load To Local Disk",         'T', menubar_cb, mo_binary_transfer },
  530.   { "----" },
  531.   { "#Delay Image Loading",        'D', menubar_cb, mo_delay_image_loads },
  532.   { "Load Images In Current",      'L', menubar_cb, mo_expand_images_current },
  533.   { "----" },
  534.   { "Reload Config Files",         'R', menubar_cb, mo_re_init },
  535.   { "----" },
  536.   { "Flush Image Cache",           'I', menubar_cb, mo_clear_image_cache },
  537.   { "Clear Global History...",     'C', menubar_cb, mo_clear_global_history },
  538.   { "----" },
  539.   { "Fonts",                       'F', NULL, NULL, fnts_menuspec },
  540.   { "Anchor Underlines",           'A', NULL, NULL, undr_menuspec }, 
  541.   { NULL },
  542. };
  543.  
  544. static XmxMenubarStruct navi_menuspec[] =
  545. {
  546.   { "Back",                    'B', menubar_cb, mo_back },
  547.   { "Forward",                 'F', menubar_cb, mo_forward },
  548.   { "----" },   
  549.   { "Home Document",           'D', menubar_cb, mo_home_document },
  550.   { "Window History...",       'W', menubar_cb, mo_history_list },
  551.   { "----" },   
  552.   { "Hotlist...",              'H', menubar_cb, mo_hotlist_postit },
  553.   { "Add Current To Hotlist",  'A', menubar_cb, mo_register_node_in_default_hotlist },
  554.   { "----" },   
  555.   { "Internet Starting Points",      'I', menubar_cb, mo_network_starting_points },
  556.   { "Internet Resources Meta-Index", 'M', menubar_cb, mo_internet_metaindex },
  557.   { NULL },
  558. };
  559.  
  560. static XmxMenubarStruct help_menuspec[] =
  561. {
  562.   { "About...",      'A', menubar_cb, mo_help_about },
  563.   { "Manual...",     'M', menubar_cb, mo_mosaic_manual },
  564.   { "----" },
  565.   { "What's New...", 'W', menubar_cb, mo_whats_new },
  566.   { "Demo...",       'D', menubar_cb, mo_mosaic_demopage },
  567.   { "----" },
  568.   { "On Version...", 'V', menubar_cb, mo_help_onversion },
  569.   { "On Window...",  'O', menubar_cb, mo_help_onwindow },
  570.   { "On FAQ...",     'F', menubar_cb, mo_help_faq },
  571.   { "----" },
  572.   { "On HTML...",    'H', menubar_cb, mo_help_html },
  573.   { "On URLs...",    'U', menubar_cb, mo_help_url },
  574.   { "----" },
  575.   { "Mail Developers...",   'M', menubar_cb, mo_whine },
  576.   { NULL },
  577. };
  578.  
  579. static XmxMenubarStruct anno_menuspec[] =
  580. {
  581.   { "Annotate...",              'A', menubar_cb, mo_annotate },
  582. #ifdef HAVE_AUDIO_ANNOTATIONS
  583.   { "Audio Annotate...",        'u', menubar_cb, mo_audio_annotate },
  584. #endif
  585.   { "----" },
  586.   { "Edit This Annotation...",  'E', menubar_cb, mo_annotate_edit },
  587.   { "Delete This Annotation...",'D', menubar_cb, mo_annotate_delete },
  588.   { NULL },
  589. };
  590.  
  591. static XmxMenubarStruct menuspec[] =
  592. {
  593.   { "File",      'F', NULL, NULL, file_menuspec },
  594.   { "Options",   'O', NULL, NULL, opts_menuspec },
  595.   { "Navigate",  'N', NULL, NULL, navi_menuspec },
  596.   { "Annotate",  'A', NULL, NULL, anno_menuspec },
  597.   { "Help",      'H', NULL, NULL, help_menuspec },
  598.   /* Dummy submenu. */
  599.   { NULL,       NULL, NULL, NULL, NULL },
  600.   { NULL },
  601. };
  602. #endif
  603.  
  604. /* ----------------------- simple menubar interface ----------------------- */
  605.  
  606. #if 0
  607.  
  608. static XmxMenubarStruct file_simple_menuspec[] =
  609. {
  610.   { "Clone Window",       'C', menubar_cb, mo_clone_window },
  611.   { "----" },
  612.   { "Search...",          'S', menubar_cb, mo_search },
  613.   { "----" },
  614.   { "Close Window",       'W', menubar_cb, mo_close_window },
  615.   { "Exit Program...",    'E', menubar_cb, mo_exit_program },
  616.   { NULL },
  617. };
  618.  
  619. static XmxMenubarStruct navi_simple_menuspec[] =
  620. {
  621.   { "Back",                    'B', menubar_cb, mo_back },
  622.   { "Forward",                 'F', menubar_cb, mo_forward },
  623.   { "----" },   
  624.   { "Home Document",           'D', menubar_cb, mo_home_document },
  625.   { "----" },   
  626.   { "Window History...",       'W', menubar_cb, mo_history_list },
  627.   { "----" },
  628.   { "Hotlist...",              'H', menubar_cb, mo_hotlist_postit },
  629.   { "Add Document To Hotlist", 'A', menubar_cb, mo_register_node_in_default_hotlist },
  630.   { NULL },
  631. };
  632.  
  633. static XmxMenubarStruct opts_simple_menuspec[] =
  634. {
  635.   { "#Binary Transfer Mode",       'B', menubar_cb, mo_binary_transfer },
  636.   { NULL },
  637. };
  638.  
  639. static XmxMenubarStruct help_simple_menuspec[] =
  640. {
  641.   { "About...",      'A', menubar_cb, mo_help_about },
  642.   { "Manual...",     'M', menubar_cb, mo_mosaic_manual },
  643.   { "----" },
  644.   { "What's New...", 'W', menubar_cb, mo_whats_new },
  645.   { "Demo...",       'D', menubar_cb, mo_mosaic_demopage },
  646.   { "----" },
  647.   { "On Version...", 'V', menubar_cb, mo_help_onversion },
  648.   { "On Window...",  'O', menubar_cb, mo_help_onwindow },
  649.   { "On FAQ...",     'F', menubar_cb, mo_help_faq },
  650.   { NULL },
  651. };
  652.  
  653. static XmxMenubarStruct anno_simple_menuspec[] =
  654. {
  655.   { "Annotate...",              'A', menubar_cb, mo_annotate },
  656. #ifdef HAVE_AUDIO_ANNOTATIONS
  657.   { "Audio Annotate...",        'u', menubar_cb, mo_audio_annotate },
  658. #endif
  659.   { "----" },
  660.   { "Edit This Annotation...",  'E', menubar_cb, mo_annotate_edit },
  661.   { "Delete This Annotation...",'D', menubar_cb, mo_annotate_delete },
  662.   { NULL },
  663. };
  664.  
  665. static XmxMenubarStruct simple_menuspec[] =
  666. {
  667.   { "File",      'F', NULL, NULL, file_simple_menuspec },
  668.   { "Navigate",  'N', NULL, NULL, navi_simple_menuspec },
  669.   { "Options",   'O', NULL, NULL, opts_simple_menuspec },
  670.   { "Annotate",  'A', NULL, NULL, anno_simple_menuspec },
  671.   { "Help",      'H', NULL, NULL, help_simple_menuspec },
  672.   /* Dummy submenu. */
  673.   { NULL,       NULL, NULL, NULL, NULL },
  674.   { NULL },
  675. };
  676.  
  677. #endif
  678.  
  679. /* -------------------- mo_make_document_view_menubar --------------------- */
  680.  
  681. /* We now allow a single customizable menu.  
  682.  
  683.    First choice for the spec file is the value of the resource
  684.    documentsMenuSpecfile.
  685.    If that doesn't exist, second choice is the value of the
  686.    environment variable MOSAIC_DOCUMENTS_MENU_SPECFILE.
  687.    If *that* doesn't exist, third choice is specified in 
  688.    #define DOCUMENTS_MENU_SPECFILE. */
  689.  
  690. static mo_status mo_file_exists (char *filename)
  691. {
  692.   struct stat buf;
  693.   int r;
  694.  
  695.   r = stat (filename, &buf); 
  696.   if (r != -1)
  697.     return mo_succeed;
  698.   else
  699.     return mo_fail;
  700. }
  701.  
  702. static void mo_grok_menubar (char *filename)
  703. {
  704.   FILE *fp;
  705.   char line[MO_LINE_LENGTH];
  706.   char *status;
  707.   XmxMenubarStruct *menu;
  708.   int count;
  709.  
  710.   fp = fopen (filename, "r");
  711.   if (!fp)
  712.     goto screwed_no_file;
  713.  
  714.   /* Make the menu. */
  715.   menu = (XmxMenubarStruct *) malloc 
  716.     (MAX_DOCUMENTS_MENU_ITEMS * sizeof (XmxMenubarStruct));
  717.   count = 0;
  718.   
  719.   /* File consists of alternating titles and URL's.
  720.      A title consisting of at least two leading dashes
  721.      is a separator. */
  722.   while (1)
  723.     {
  724.       status = fgets (line, MO_LINE_LENGTH, fp);
  725.       if (!status || !(*line))
  726.         goto done;
  727.  
  728.       if (strlen (line) >= 2 &&
  729.           line[0] == '-' &&
  730.           line[1] == '-')
  731.         {
  732.           /* It's a separator. */
  733.           menu[count].namestr = "----";
  734.           menu[count].mnemonic = 0;
  735.           menu[count].func = 0;
  736.           menu[count].data = 0;
  737.           menu[count].sub_menu = 0;
  738.         }
  739.       else
  740.         {
  741.           /* That's the title. */
  742.           menu[count].namestr = strdup (line);
  743.           /* Wipe out trailing newline. */
  744.           menu[count].namestr[strlen(line)-1] = '\0';
  745.           menu[count].mnemonic = 0;
  746.           menu[count].func = (void (*)())menubar_cb;
  747.           menu[count].data = count + DOCUMENTS_MENU_COUNT_OFFSET;
  748.           menu[count].sub_menu = 0;
  749.           
  750.           status = fgets (line, MO_LINE_LENGTH, fp);
  751.           if (!status || !(*line))
  752.             {
  753.               /* Oops, something went wrong. */
  754.               menu[count].namestr = 0;
  755.               
  756.               goto done;
  757.             }
  758.           
  759.           /* There's a URL. */
  760.           urllist[count] = strdup (line);
  761.           urllist[count][strlen(line)-1] = '\0';
  762.         }
  763.  
  764.       /* Count increases. */
  765.       count++;
  766.     }
  767.  
  768.  done:
  769.   /* Make sure we get a NULL in the right place. */
  770.   menu[count].namestr = 0;
  771.   fclose (fp);
  772.   if (count > 0)
  773.     {
  774.       if (Rdata.simple_interface)
  775.         {
  776.           simple_menuspec[5].namestr = "Documents";
  777.           simple_menuspec[5].mnemonic = 'D';
  778.           simple_menuspec[5].func = 0;
  779.           simple_menuspec[5].data = 0;
  780.           simple_menuspec[5].sub_menu = menu;
  781.         }
  782.       else
  783.         {
  784.           menuspec[5].namestr = "Documents";
  785.           menuspec[5].mnemonic = 'D';
  786.           menuspec[5].func = 0;
  787.           menuspec[5].data = 0;
  788.           menuspec[5].sub_menu = menu;
  789.         }
  790.     }
  791.   return;
  792.  
  793.  screwed_open_file:
  794.   fclose (fp);
  795.   return;
  796.  
  797.  screwed_no_file:
  798.   return;
  799. }
  800.  
  801.  
  802. static void mo_try_to_grok_menubar (void)
  803. {
  804.   char *filename = Rdata.documents_menu_specfile;
  805.   
  806.   if (filename && mo_file_exists (filename))
  807.     {
  808.       mo_grok_menubar (filename);
  809.     }
  810.   else
  811.     {
  812.       filename = getenv ("MOSAIC_DOCUMENTS_MENU_SPECFILE");
  813.       if (filename && mo_file_exists (filename))
  814.         {
  815.           mo_grok_menubar (filename);
  816.         }
  817.       else
  818.         {
  819.           filename = DOCUMENTS_MENU_SPECFILE;
  820.           if (filename && mo_file_exists (filename))
  821.             {
  822.               mo_grok_menubar (filename);
  823.             }
  824.         }
  825.     }
  826.  
  827.   return;
  828. }
  829.  
  830. static int grokked_menubar = 0;
  831.  
  832. XmxMenuRecord *mo_make_document_view_menubar (Widget form)
  833. {
  834.   /* If we've never tried to set up the user's configurable menubar by
  835.      loading menuspec[5], give it a shot now. */
  836.   if (!grokked_menubar)
  837.     {
  838.       grokked_menubar = 1;
  839.  
  840.       mo_try_to_grok_menubar ();
  841.     }
  842.  
  843.   return XmxRMakeMenubar 
  844.     (form, Rdata.simple_interface ? simple_menuspec : menuspec);
  845. }
  846.